<template>
  <el-switch v-model="value" :loading="loading" @change="onChange"/>
</template>

<script setup lang="ts">
import {defineEmits, ref} from "vue";
import {tableColumn} from "@/components/table/column";

const props = defineProps<{
  column: tableColumn
}>()

const value = ref<boolean>(false)
const loading = ref<boolean>(false)

const onChange = async (val: boolean) => {
  value.value = val
  loading.value = true

  if (
      props.column.callback &&
      Object.prototype.toString.call(props.column.callback) ===
      '[object Function]'
  ) {
    await props.column.callback(val)
    loading.value = false
  }
}

</script>

<style scoped>

</style>
